export const Layout = () => import('@/layout/index.vue')

import type { App } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
	{
		path: '/login',
		component: () => import('@/views/login/index.vue'),
		meta: { hidden: true },
	},
	{
		path: '/',
		component: Layout,
		redirect: '/home',
		children: [
			{
				path: 'home',
				component: () => import('@/views/home/index.vue'),
				name: 'Home',
				meta: { title: '首页' },
			},
			{
				path: '401',
				component: () => import('@/views/error-page/401.vue'),
				meta: { hidden: true },
			},
			{
				path: '404',
				component: () => import('@/views/error-page/404.vue'),
				meta: { hidden: true },
			},
		],
	},
]

const router = createRouter({
	history: createWebHashHistory(),
	routes: constantRoutes,
	scrollBehavior: () => ({ top: 0, left: 0 }),
})

export function setupRouter(app: App<Element>) {
	app.use(router)
}
export default router
